#pragma once

#include "V4L2Camera.hpp"
#include "camera_manage_type.h"
#include "cbb_camera_comm.h"
#include <atomic>
#include <functional>
#include <thread>
#include <vector>
class CameraController {
  public:
    CameraController();
    ~CameraController();

    void initCamera(const MultiCameraConfig &config);
    void startCapture(std::function<void(int, const CbbCameraFrame_t &)> frameCallback);
    void stopCapture();
    bool updateCameraConfig(int cameraId, const CameraConfig &config);

  private:
    std::vector<std::unique_ptr<V4L2Camera>> m_devices;
    std::vector<std::thread> m_captureThreads;
    std::atomic<bool> m_isCapturing;
    std::function<void(int, const CbbCameraFrame_t &)> m_frameCallback;
    void captureLoop(int cameraId);
    V4L2CameraConfig convertToV4L2CameraConfig(const CameraConfig &config);
    V4L2Camera *getCamera(int cameraId);
};